package com.asset.dispoal.file.user.domain.service.common;

import com.asset.dispoal.file.user.domain.db.entity.FileUser;
import com.asset.dispoal.file.user.domain.db.mapper.FileUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import tech.mhuang.pacebox.springboot.protocol.Result;

import java.util.Date;

@Component
public class FileUserCommand {

    @Autowired
    private FileUserMapper fileUserMapper;


    public Result loginUser(String username, String password) {
        FileUser fileUser = fileUserMapper.getUsername(username);
        if (fileUser == null) {
            return Result.faild("账号错误");
        }
        if (fileUser.getPassword().equals(password)) {
            if (fileUser.getExpireTime().after(new Date())) {
                return Result.faild("账号已过期、请续费....");
            }
            return Result.ok(fileUser);
        }
        return Result.faild("密码错误");
    }
}
